#pragma once
/*
 * Created by: Mark Lavrynenko
 * Email:	MarkLavrinenko@gmail.com
 * Project:	  Huffman
*/

#include "archiver.h"
#include "IHTreeCallBack.h"

class FrequencyTable;
class CodingTable;
class HTree;

class HuffmanArchiver :
	public Archiver, public  IHTreeCallBack
{
public:
	HuffmanArchiver();
	virtual ~HuffmanArchiver(void);
	virtual void archive(DataSource* s, DataTarget* t);
	virtual void unarchive(DataSource* s, DataTarget* t);
	virtual void acceptFinishedByte(uint8_t byte);
	virtual void HuffmanArchiver::process(DataSource* s, DataTarget*t, ArchivingMode mode);
private:
	FrequencyTable* m_table;
	CodingTable* m_codingTable;
	size_t m_decodedSymbols;
	size_t m_estimatedSymbols;
	// safe or not
	DataSource* m_source;
	DataTarget* m_target;
	HTree* m_tree;
	void writeFrequencyTable(FrequencyTable* table, DataTarget* target);
};

